#include "MainWindow.h"
#include "ui_MainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setupActions();

    ui->mainToolBar->addAction(m_actionNewConnection);

    //m_connection = new XHCPConnection(this);
    //m_connection->setConnectionOptions(QHostAddress("127.0.0.1"));

    //connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(onConnectButtonClick()));
    //connect(ui->disconnectButton, SIGNAL(clicked()), this, SLOT(onDiconnectButtonClick()));
    //connect(ui->listAllDevsButton, SIGNAL(clicked()), m_connection, SLOT(requestListAllDevs()));
}

MainWindow::~MainWindow()
{
    delete ui;
    if(m_connection) {
        if(m_connection->isOpen())
            m_connection->close();
        delete m_connection;
    }
}

void MainWindow::setupActions()
{
    m_actionNewConnection = new QAction(this);
    m_actionNewConnection->setText(tr("New connection"));
    m_actionNewConnection->setToolTip(tr("New connection"));
    //m_actionNewConnection->setIcon(QIcon(":/icon/new_connection"));
    connect(m_actionNewConnection, SIGNAL(triggered()), this, SLOT(onActionNewConnectionTriggered()));
}

void MainWindow::onActionNewConnectionTriggered()
{

}


void MainWindow::onConnectButtonClick()
{
    m_connection->open();
}

void MainWindow::onDiconnectButtonClick()
{
    m_connection->close();
}

void MainWindow::onListAllDevsButtonClick()
{
    m_connection->requestListAllDevs();
}
